from fasu.models import DisposalSubjectModel, CaseInfoModel, FileModel, PrincipalModel, MediationModel, PartModel, \
    BatchModel, CourtsModel, PlainCompanyModel
from dvadmin.utils.serializers import CustomModelSerializer

from rest_framework import serializers


class FileSerializer(serializers.ModelSerializer):
    class Meta:
        model = FileModel
        fields = '__all__'


class DisposalSubjectModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    class Meta:
        model = DisposalSubjectModel
        fields = "__all__"
        read_only_fields = ["id"]  # 导入专用————排除ID


class DisposalSubjectModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = DisposalSubjectModel
        fields = '__all__'


class CaseInfoModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    # *****************************************
    # 此方法用作于数据库多选时候获取其他字段：如获取性别库中的其他字段, get_depart_display中 depart为数据库的表头
    # depart = serializers.CharField(source='get_depart_display')

    depart_id = serializers.CharField(source='depart.disposal_subject_id', read_only=True, default=None)
    depart_name = serializers.CharField(source='depart.disposal_subject_name', read_only=True, default=None,
                                        help_text='主体名称')

    # *****************************************
    # depart = DisposalSubjectModelSerializer()

    class Meta:
        model = CaseInfoModel
        fields = "__all__"


class CaseInfoModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = CaseInfoModel
        fields = '__all__'


class PrincipalModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    class Meta:
        model = PrincipalModel
        fields = "__all__"


class PrincipalModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = PrincipalModel
        fields = '__all__'


class MediationModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    class Meta:
        model = MediationModel
        fields = "__all__"


class MediationModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = MediationModel
        fields = '__all__'


class PartModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    class Meta:
        model = PartModel
        fields = "__all__"


class PartModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = PartModel
        fields = '__all__'


class BatchModelSerializer(CustomModelSerializer):
    """
    序列化器
    """

    # company_id = PrincipalModelSerializer()
    company_id = serializers.CharField(source='company_id.companyname', read_only=True, default=None, help_text='委案公司信息')
    company_name = serializers.CharField(source='company_id.companyname', read_only=True, default=None)
    company_code = serializers.CharField(source='company_id.companycode', read_only=True, default=None)

    mediation_id = serializers.CharField(source='mediation_id.uuid', read_only=True, default=None, help_text='调解组织')
    mediation_name = serializers.CharField(source='mediation_id.mediation_name', read_only=True, default=None)
    mediation_code = serializers.CharField(source='mediation_id.mediation_code', read_only=True, default=None)

    class Meta:
        model = BatchModel
        fields = "__all__"


class BatchModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = BatchModel
        fields = '__all__'


class CourtsModelSerializer(CustomModelSerializer):
    """
    序列化器
    """


    class Meta:
        model = CourtsModel
        fields = "__all__"


class CourtsModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = CourtsModel
        fields = '__all__'


class PlainCompanyModelSerializer(CustomModelSerializer):
    """
    序列化器
    """


    class Meta:
        model = CourtsModel
        fields = "__all__"


class PlainCompanyModelCreateUpdateSerializer(CustomModelSerializer):
    """
    创建/更新时的列化器
    """

    class Meta:
        model = CourtsModel
        fields = '__all__'

